package com.simon.annual.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Service;

import com.simon.annual.entity.ReportDefinition;
import com.simon.annual.repositoy.IReportDefinitionRepositoy;
import com.simon.annual.service.ICompanyPublicInfo;

/**
 * 处理释义项目
 * */
@Service
public class ExplanationImpl{

	@Resource
	private IReportDefinitionRepositoy reportDefinition;	
	@Resource
	private ICompanyPublicInfo cmpanyPublicInfo;
	
	public Element analysis(Document doc, int companyPtrId) {
		
//		Element toc = doc.select("TOC").last();
//		Element definition = toc.nextElementSibling();
		//释义项目
		Elements  definitions = doc.getElementsMatchingOwnText("\u91CA\u4E49\u9879\u76EE");//释义 项目
		Element de = definitions.first();
		if(de.tagName().equals("p")){
			de = de.parent();
		}
		Element definition = de.parent().parent().parent();
		definition = cmpanyPublicInfo.getNextTag(definition, definition);
		Elements tr = definition.select("table tr");
		List<ReportDefinition>  reportDefinitionList = new ArrayList<ReportDefinition>();
		for (int i = 1; i < tr.size(); i++) {
			ReportDefinition tReportDefinition = new ReportDefinition();
			Elements eTd = tr.get(i).children();
			tReportDefinition.setAbbr(eTd.get(0).text());
			tReportDefinition.setMeaning(eTd.last().text());
			tReportDefinition.setProjectScopeId(companyPtrId);
			reportDefinitionList.add(tReportDefinition);
		}
		reportDefinition.save(reportDefinitionList);
		return null;
	}

}
